package com.ssy.lingxi.member.merchant.api.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * 会员权益积分消费类型枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-11-20
 */
public enum MemberRightSpendTypeEnum {
    /**
     * 积分订单 - 1
     */
    ORDER(1, "积分订单"),

    /**
     * 积分兑换优惠券 - 2
     */
    COUPON(2, "积分兑换优惠券"),

    /**
     * 积分抵扣订单金额 - 3
     */
    DEDUCTION_AMOUNT(3, "积分抵扣订单金额");

    MemberRightSpendTypeEnum(Integer typeEnum, String typeName) {
        this.typeEnum = typeEnum;
    }

    /**
     * 权益使用类型
     */
    private Integer typeEnum;

    public Integer getTypeEnum() {
        return typeEnum;
    }

    public void setTypeEnum(Integer typeEnum) {
        this.typeEnum = typeEnum;
    }

    public String getTypeName() {
        return LanguageHolder.getName(this.getClass(), this.getTypeEnum());
    }

    public static MemberRightSpendTypeEnum parse(Integer typeEnum) {
        return Arrays.stream(MemberRightSpendTypeEnum.values()).filter(e -> e.getTypeEnum().equals(typeEnum)).findFirst().orElse(null);
    }

    public static String getNameByCode(Integer typeEnum) {
        return LanguageHolder.getName(MemberRightSpendTypeEnum.class, typeEnum);
    }
    public static boolean isOrder(Integer typeEnum) {
        return Stream.of(MemberRightSpendTypeEnum.ORDER,MemberRightSpendTypeEnum.DEDUCTION_AMOUNT).filter(o ->o.getTypeEnum().equals(typeEnum)).findFirst().isPresent();
    }
}
